﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace ProjectRoughWork
{
    class Cohesion : AIState
    {
        public Cohesion(SquadActor[] initSquad) : base()
        {
            squad = initSquad; 
        }

        public override void VOnUpdate()
        {
            //Calculate the center of the squad

            Vector3 center = Vector3.Zero; 
            for (int index = 0; index < 3; index++)
            {
                center += squad[index].getPosition();
            }

            center.X /= 3;
            center.Z /= 3;

            Vector3 cohesionAdjust = Vector3.Zero;

            //Move the actor closer to the center of the squad

            for (int index = 0; index < 3; index++)
            {
                cohesionAdjust = (center - squad[index].getPosition());
                cohesionAdjust.Normalize();
                cohesionAdjust *= squad[index].MaxAcceleration;
                squad[index].setVelocity(squad[index].getVelocity() + cohesionAdjust);
            }

            base.VOnUpdate();
        }

        //Data Members

        SquadActor[] squad;     //The Squad being influenced
    }
}
